<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

<div class="login">
    <p>
        账号：<input type="text" class="user">
    </p>
    <p>
        密码：<input type="text" class="pass">
    </p>
    <p>
        <button class="btn">登录</button>
    </p>
</div>

<script src="https://cdn.bootcdn.net/ajax/libs/axios/1.3.6/axios.js"></script>
<script>

let user = document.querySelector('.user');
let pass = document.querySelector('.pass');
let btn = document.querySelector('.btn');

btn.onclick = function (){
    // 发送登录请求
    axios({
        method: 'get',
        params: {
            username: user.value,
            password: pass.value
        },
        url: 'http://localhost:9090/users/login'
    })
    .then((response)=>{
        let {data} = response;

        // 判断登录是否成功
        if (data.code === 1) {
            // 登录成功，将token存储在本地，跳转到首页
            localStorage.setItem('token',data.token);
            location.href = './index.html';
        } else {
            // 登录失败
            alert(data.msg);
        }
    })
}

</script>
</body>
</html>